﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Entity;
using NLBS.Framework;

namespace NLBS.Validate
{
   public class GuestBookValidate:ValidateTemplete<GuestBook>
    {
       public GuestBookValidate(Action act, int keyID)
       {
           this.Act = act;
           this.keyID = keyID;
       }

        public override void checkPower()
        {
            switch (Act)
            {
                case Action.Select:
                case Action.Update:
                    if (power.Edit < 1)
                    {
                        throw new Exception("没有权限进行此操作");
                    }
                    break;
            }
        }

        public void checkPostDuration()
        {
            ValidateHelper.checkPostDuration();
        }

        public override void checkArgument()
        {

        }

        public void checkLogin()
        {
            //commentValidate.checkLogin();
        }

        public override void checkEntity()
        {
            if (this.Entity == null)
            {
                throw new Exception("该留言不存在");
            }
        }

        public override void checkPowerAgain()
        {
            User user = BlogInfo.Instance().CurrentUser;
            switch (Act)
            {
                case Action.Select:
                case Action.Update:
                    if (user.UserID != this.Entity.UserID && power.Edit < 2)
                    {
                        throw new Exception("没有权限进行此操作");
                    }
                    break;
                case Action.Delete:
                    if (user.UserID != this.Entity.UserID && user.Group.GroupID != 1 && power.Delete < 2)
                    {
                        throw new Exception("没有权限进行此操作");
                    }
                    break;
            }
        }
    }
}
